#include "gui/util/GUIObjectDrawer.h"

namespace gui {

GUIObjectDrawer::GUIObjectDrawer(SurfaceFactory* surfaceFactory) {
	this->surfaceFactory = surfaceFactory;
}

GUIObjectDrawer::~GUIObjectDrawer() {

}

Surface* GUIObjectDrawer::drawGUIObject(GUIObject* object) {
	Surface* surface = NULL;
	Portion portion;
	portion.x = object->getXPos();
	portion.y = object->getYPos();
	portion.w = -1;
	portion.h = -1;
	// Si tiene una textura (fileName) seteada.
	if (object->getTexture().compare("") != 0) {
		surface = this->surfaceFactory->createSurface(object->getTexture(), portion);
	} else {
		surface = this->surfaceFactory->createSurface(portion);
		// Colores: object->getRColor(), object->getGColor(), object->getBColor()
	}
	// Roto la imagen del GUIObject (si tiene rotacion 0 no hace nada).
	surface->rotate(object->getRotation());
	// Aplico transparencia si la hay.
	if (object->getTextureHasTransparentColor()) {
		surface->setTransparentColor(object->getTextureTransparentColor());
	}
	return surface;
}

}
